package com.s3u4.demo.zookeeper.base;

import com.s3u4.demo.zookeeper.ZkConfig;
import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.List;

/**
 * 成员列表
 * Created by Captain on 01/08/2017.
 */
public class ListGroup extends ConnectionWatcher {

    public void list(String path)  {
        List<String> children;
        try {
            children = zooKeeper.getChildren(path,false);
        } catch (KeeperException e) {
            System.out.println("KeeperException..." + e.getClass());
            if ( e.getClass() == KeeperException.NoNodeException.class ){
                System.out.println("No Valid ZNode");
            }
            return;
        } catch (InterruptedException e) {
            System.out.println("InterruptedException...");
            e.printStackTrace();
            return;
        }

        for(String child : children){
            System.out.println( "path["+ path + "]'s child : " + child );
        }

    }

    public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
        ListGroup listGroup = new ListGroup();
        listGroup.connect(ZkConfig.ZK_HOST);
        listGroup.list("/dubbo/cn.jpush.portal.api.AppService");
        listGroup.close();
    }


}
